package com.tianji.controller;

import cn.hutool.core.collection.CollUtil;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/embedding")
public class EmbeddingController {
    @Autowired
    private VectorStore vectorStore;
    @PostMapping
    public void addEmbeddingToEs(@RequestParam List<String> messages) {
        if (CollUtil.isEmpty(messages)) return;
        List<Document> list = messages.stream().map(m -> {
            return Document.builder().text(m).build();
        }).toList();
        vectorStore.add(list);
    }
}
